﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XPathAutoSuggest {

    /// <summary>
    /// A simple class to allow a form to bind to a command that starts working with empty XML
    /// </summary>
    public class NewCommand : CommandBase {
        /// <summary>
        /// Constructor takes an instance of the view model hosting the guts of the code
        /// </summary>
        /// <param name="newModelView">View model</param>
        public NewCommand(IXPathToolVm newModelView)
            : base(newModelView) {
        }

        /// <summary>
        /// Does the actual work
        /// </summary>
        /// <param name="parameter">Not used</param>
        public override bool CanExecute(object parameter) {
            return ((IFileIoCommands)_MV).NewCanExecute();
        }

        /// <summary>
        /// Instructs the ModelView to set its state to reflect new, empty XML with no file name
        /// </summary>
        /// <param name="parameter"></param>
        public override void Execute(object parameter) {
            ((IFileIoCommands)_MV).NewExecute();
        }
    }

    /// <summary>
    /// A simple class to allow a form to bind to a command that loads an XML file
    /// </summary>
    public class OpenCommand : CommandBase {
        /// <summary>
        /// Constructor takes an instance of the view model hosting the guts of the code
        /// </summary>
        /// <param name="newModelView">View model</param>
        public OpenCommand(IXPathToolVm newModelView)
            : base(newModelView) {
        }

        /// <summary>
        /// Whether the command can execute
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>True if the command can fire</returns>
        public override bool CanExecute(object parameter) {
            return ((IFileIoCommands)_MV).OpenCommandCanExecute();
        }

        /// <summary>
        /// Does the actual work
        /// </summary>
        /// <param name="parameter">Not used</param>
        public override void Execute(object parameter) {
            ((IFileIoCommands) _MV).OpenCommandExecute();
        }
    }

    /// <summary>
    /// A simple class to allow a form to bind to a command that saves users' XML to a file
    /// </summary>
    public class SaveCommand : CommandBase {
        /// <summary>
        /// Constructor takes an instance of the view model hosting the guts of the code
        /// </summary>
        /// <param name="newModelView">View model</param>
        public SaveCommand(IXPathToolVm newModelView) : base(newModelView) { }

        /// <summary>
        /// Whether the command can execute
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>True if the command can fire</returns>
        public override bool CanExecute(object parameter) {
            return ((IFileIoCommands)_MV).SaveCommandCanExecute();
        }

        /// <summary>
        /// Does the actual work
        /// </summary>
        /// <param name="parameter">The XML to save</param>
        public override void Execute(object parameter) {
            ((IFileIoCommands)_MV).SaveCommandExecute();
        }
    }


    /// <summary>
    /// A simple class to allow a form to bind to a command that closes the application
    /// </summary>
    public class CloseCommand : CommandBase {
        /// <summary>
        /// Constructor takes an instance of the view model hosting the guts of the code
        /// </summary>
        /// <param name="newModelView">View model</param>
        public CloseCommand(IXPathToolVm newModelView) : base(newModelView) { }

        /// <summary>
        /// Whether the command can execute
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>True if the command can fire</returns>
        public override bool CanExecute(object parameter) {
            return ((IFileIoCommands)_MV).CloseCommandCanExecute();
        }

        /// <summary>
        /// Does the actual work
        /// </summary>
        /// <param name="parameter">Not used</param>
        public override void Execute(object parameter) {
            ((IFileIoCommands)_MV).CloseCommandExecute();
        }
    }
    /// <summary>
    /// A simple class to allow a form to bind to a command that saves the users' XML after prompting for new file name
    /// </summary>
    public class SaveAsCommand : CommandBase {
        /// <summary>
        /// Constructor takes an instance of the view model hosting the guts of the code
        /// </summary>
        /// <param name="newModelView">View model</param>
        public SaveAsCommand(IXPathToolVm newModelView) : base(newModelView) { }

        /// <summary>
        /// Whether the command can execute
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>True if the command can fire</returns>
        public override bool CanExecute(object parameter) {
            return ((IFileIoCommands)_MV).SaveAsCommandCanExecute();
        }

        /// <summary>
        /// Works with the ModelView to save users' XML to file under a new name
        /// </summary>
        /// <param name="parameter">Not used</param>
        public override void Execute(object parameter) {
            ((IFileIoCommands)_MV).SaveAsCommandExecute();
        }
    }
}
